// import { mapMutations } from "vuex"

export default{
	// 开启命名空间
	namespaced:true,
	
	// 数据
	state:()=>({
		address: JSON.parse(uni.getStorageSync('address')||'{}'),
		token:'',
		// 用户的信息对象
		userinfo:JSON.parse(uni.getStorageSync('userinfo') || '{}')
	
	}),
	
	// 方法
	mutations:{
		// 更新收获地址u
		updateAddress(state,address){
			state.address=address
			
			// 通过this.commit('m_user/saveAddressToStorage')调用
			this.commit('m_user/saveAddressToStorage')
		},
		
		// 定义将 address持久化存储到本地 mutations 方法中
		saveAddressToStorage(state){
			uni.setStorageSync('address',JSON.stringify(state.address))
		},
		// 更新数据
		updateUserInfo(state,userinfo){
			state.userinfo = userinfo,
			
			this.commit('m_user/saveUserInfoToStorage')
		},
		saveUserInfoToStorage(state){
			uni.setStorageSync('userinfo',JSON.stringify(state.userinfo))
		}
	},
	
	getters:{
		addstr(state){
			if(!state.address.provinceName) return ''
				
			return state.address.provinceName + state.address.cityName + state.address.countyName + state.address.detailInfo
		}
	}
}